package com.itheima.ydd.controller;


import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.YddCate;
import com.itheima.ydd.service.IYddCateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/ydd_cate")
public class YddCateController {

    @Autowired
    private IYddCateService cateService;

    /**
     * @description: 分页查询及条件查询
     * @author: 黄伟兴
     * @date: 2022/9/8 12:38
     * @param: [catename, page, limit]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/list")
    public ResultData getList(@RequestParam String catename, @RequestParam String page, @RequestParam String limit){
      return   cateService.getList(catename,page,limit);
    }

    /**
     * @description: 获取分类详细信息
     * @author: 黄伟兴
     * @date: 2022/9/8 13:05
     * @param: [id]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/rowInfo")
    public ResultData getDetail(@RequestParam Integer id){
     return    cateService.getDetail(id);
    }

    /**
     * @description: 修改分类信息
     * @author: 黄伟兴
     * @date: 2022/9/8 13:19
     * @param: []
     * @return: com.itheima.ydd.common.ResultData
     **/
    @PostMapping("/update")
    public ResultData update(@RequestBody YddCate yddCate){
        return cateService.updateYddCate(yddCate);
    }

    /**
     * @description: 删除分类
     * @author: 黄伟兴
     * @date: 2022/9/8 13:37
     * @param: [id]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/del")
    public  ResultData delete(@RequestParam Integer id){
        return cateService.delete(id);
    }

    /**
     * @description: 添加新分类
     * @author: 黄伟兴
     * @date: 2022/9/8 13:51
     * @param: [yddCate]
     * @return: com.itheima.ydd.common.ResultData
     **/
    @PostMapping("/add")
    public ResultData add(@RequestBody YddCate yddCate){
        return  cateService.add(yddCate);
    }

    /**
     * @description: 分类信息-全部
     * @author: 黄伟兴
     * @date: 2022/9/8 14:17
     * @param: []
     * @return: com.itheima.ydd.common.ResultData
     **/
    @GetMapping("/all")
    public ResultData getAll(){
        return  cateService.getAll();
    }
}
